package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.Product;
import com.woniu.mapper.ProductMapper;
import com.woniu.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huangjianbin
 * @since 2023-02-07 11:59:17
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    ProductMapper productMapper;

    @Override
    public Page<Product> pageData(Integer currentPage, Integer pageSize) {
        Page<Product> productPage = new Page<>(currentPage,pageSize);

        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();

        Page<Product> pageData = productMapper.selectPage(productPage, queryWrapper);

        return pageData;
    }

    @Override
    public Page<Product> search(Integer currentPage, Integer pageSize, String keyword) {
        Page<Product> productPage = new Page<>(currentPage, pageSize);
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("productname",keyword);

        Page<Product> pageData = productMapper.selectPage(productPage, queryWrapper);
        return pageData;
    }

}
